﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeBehind="OrderMaterialDetail.aspx.cs" Inherits="UdrinkWater_Project.Admin.OrderMaterialDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    // <![CDATA[
    function showeditpop() {
        editpop.Show();
    }
    function ShowCreateAccountWindow() {
        pcCreateAccount.Show();
        tbUsername.Focus();
    }
    // ]]> 
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server" 
        ClientInstanceName="editpop" HeaderText="" 
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="TopSides">
        <ContentCollection>
<dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True">
    <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="SqlMaterialStatus0" DataTextField="M_Status_Name" 
        DataValueField="M_Status_ID">
    </asp:DropDownList>
    <dx:ASPxButton ID="ASPxButton2" runat="server" Text="แก้ไข" 
        OnClick="ASPxButton2_Click">
     <ClientSideEvents Click="function(s, e) { editpop.Hide(); }" />
    </dx:ASPxButton>
    <asp:SqlDataSource ID="SqlMaterialStatus0" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
        SelectCommand="SELECT M_Status_ID, M_Status_Name FROM TB_MaterialStatus">
    </asp:SqlDataSource>
            </dx:PopupControlContentControl>
</ContentCollection>
    </dx:ASPxPopupControl>
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" 
        HeaderText="รายละเอียดการสั่งซื้อ" Width="100%">
        <PanelCollection>
            <dx:PanelContent runat="server" SupportsDisabledAttribute="True">
                <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlOrder_Material" KeyFieldName="OrderM_Date" 
                    OnRowCommand="ASPxGridView1_RowCommand">
                    <Columns>
                        <dx:GridViewCommandColumn Caption="ทำรายการ" ShowInCustomizationForm="True" 
                            VisibleIndex="7">
                            <EditButton Text="แก้ไขสถานะ">
                            </EditButton>
                            <DeleteButton Text="ลบ" Visible="True">
                            </DeleteButton>
                            <CancelButton Text="ยกเลิก">
                            </CancelButton>
                            <UpdateButton Text="ยืนยัน">
                            </UpdateButton>
                            <ClearFilterButton Text="ยกเลิก" Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataDateColumn Caption="วันที่ / เวลาทำรายการ" 
                            FieldName="OrderM_Date" ReadOnly="True" ShowInCustomizationForm="True" 
                            VisibleIndex="0">
                            <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy HH:mm:ss" 
                                EditFormat="DateTime">
                            </PropertiesDateEdit>
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataDateColumn>
                        <dx:GridViewDataTextColumn Caption="ที่อยู่" FieldName="Address" 
                            ShowInCustomizationForm="True" VisibleIndex="1">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ตำบล" FieldName="DISTRICT_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="2">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="อำเถอ" FieldName="AMPHUR_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="3">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="จังหวัด" FieldName="PROVINCE_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="4">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataComboBoxColumn Caption="สถานะ" FieldName="M_Status_ID" 
                            ShowInCustomizationForm="True" VisibleIndex="5">
                            <PropertiesComboBox DataSourceID="SqlMaterialStatus" TextField="M_Status_Name" 
                                ValueField="M_Status_ID">
                            </PropertiesComboBox>
                        </dx:GridViewDataComboBoxColumn>
                        <dx:GridViewDataTextColumn Caption="แก้ไขสถานะ" ShowInCustomizationForm="True" 
                            VisibleIndex="6">
                            <DataItemTemplate>
                                <dx:ASPxButton ID="ASPxButton1" runat="server" Text="แก้ไขสถานะ" CommandArgument='<%# Eval("OrderM_Date") %>' CommandName="Cmd_Select">
                                    <ClientSideEvents Click="function(s, e) {
	                                        showeditpop(); }"/>
                                </dx:ASPxButton>
                            </DataItemTemplate>
                        </dx:GridViewDataTextColumn>
                    </Columns>
                    <SettingsBehavior ConfirmDelete="True" />
                    <Settings ShowFilterRow="True" />
                    <SettingsText ConfirmDelete="ยืนยันการลบ" />
                    <SettingsDetail ShowDetailRow="True" />
                    <Templates>
                        <DetailRow>
                            <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" 
                                DataSourceID="SqlDataSource1" 
                                onbeforeperformdataselect="ASPxGridView2_BeforePerformDataSelect" Width="100%">
                                <TotalSummary>
                                    <dx:ASPxSummaryItem DisplayFormat="รวม {0:#,###.00}" FieldName="TotalPrice" 
                                        ShowInColumn="รวม" SummaryType="Sum" ShowInGroupFooterColumn="รวม" />
                                </TotalSummary>
                                <Columns>
                                    <dx:GridViewDataDateColumn FieldName="OrderM_Date" Visible="False" 
                                        VisibleIndex="0">
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataTextColumn Caption="รหัสสินค้า" FieldName="Material_ID" 
                                        VisibleIndex="1">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ชื่อสินค้า" FieldName="Materail_name" 
                                        VisibleIndex="2">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Material_Count" 
                                        VisibleIndex="3">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="หน่วยนับ" FieldName="Unit_Name" 
                                        VisibleIndex="4">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ราคาต่อหน่วย" FieldName="Price" 
                                        VisibleIndex="5">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="รวม" FieldName="TotalPrice" ReadOnly="True" 
                                        VisibleIndex="6">
                                    </dx:GridViewDataTextColumn>
                                </Columns>
                                <Settings ShowFooter="True" />
                            </dx:ASPxGridView>
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                SelectCommand="SELECT TB_OrderMaterial_list.OrderM_Date, TB_OrderMaterial_list.Material_ID, TB_Material.Materail_name, TB_OrderMaterial_list.Material_Count, TB_Unit_Category.Unit_Name, TB_OrderMaterial_list.Price, TB_OrderMaterial_list.Material_Count * TB_OrderMaterial_list.Price AS TotalPrice FROM TB_OrderMaterial_list INNER JOIN TB_Material ON TB_OrderMaterial_list.Material_ID = TB_Material.Material_ID INNER JOIN TB_Unit_Category ON TB_Material.Unit = TB_Unit_Category.Unit_ID WHERE (OrderM_Date = @OrderM_Date)">
                                <SelectParameters>
                                    <asp:SessionParameter Name="OrderM_Date" SessionField="OrderM_Date" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                        </DetailRow>
                    </Templates>
                </dx:ASPxGridView>
                <asp:SqlDataSource ID="SqlOrder_Material" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                    DeleteCommand="DELETE FROM TB_Order_Material WHERE (OrderM_Date = @OrderM_Date)" 
                    SelectCommand="SELECT TB_Order_Material.OrderM_Date, TB_Order_Material.Address, TB_District.DISTRICT_NAME, TB_Aumphur.AMPHUR_NAME, TB_Province.PROVINCE_NAME, TB_Order_Material.M_Status_ID FROM TB_Order_Material INNER JOIN TB_Province ON TB_Order_Material.Province_ID = TB_Province.PROVINCE_ID INNER JOIN TB_Aumphur ON TB_Order_Material.Aumphur_ID = TB_Aumphur.AMPHUR_ID INNER JOIN TB_District ON TB_Order_Material.District_ID = TB_District.DISTRICT_ID ORDER BY TB_Order_Material.OrderM_Date DESC" 
                    UpdateCommand="UPDATE TB_Order_Material SET M_Status_ID = @M_Status_ID WHERE (OrderM_Date = @OrderM_Date)">
                    <DeleteParameters>
                        <asp:Parameter Name="OrderM_Date" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="M_Status_ID" />
                        <asp:Parameter Name="OrderM_Date" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlMaterialStatus" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                    SelectCommand="SELECT M_Status_Name, M_Status_ID FROM TB_MaterialStatus">
                </asp:SqlDataSource>
                <asp:HiddenField ID="hdvalue" runat="server" />
            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
